import request from '@/router/axios';
import {baseUrl} from '@/config/env';

export const allTaskPage = (data) => {
    return request({
            url: baseUrl + '/actProcessTask/allTaskPage',
            method: 'get',
            params: data
        }
    )
}

export const getMyTaskPage = (data) => {
    return request({
            url: baseUrl + '/actProcessTask/getMyTaskPage',
            method: 'get',
            params: data
        }
    )
}

export const add = (data) => {
    return request({
            url: baseUrl + '/actProcessTask/add',
            method: 'get',
            data: data
        }
    )
}

export const updateById = (id, data, index) => {
    return request({
            url: baseUrl + '/actProcessTask/updateById',
            method: 'put',
            data: data
        }
    )
}
export const deleteById = (id) => {
    return request({
            url: baseUrl + '/actProcessTask/deleteById/' + id,
            method: 'delete',
        }
    )
}
export const getById = (id) => {
    return request({
            url: baseUrl + '/actProcessTask/getById/' + id,
            method: 'get',
        }
    )
}
/**
 * 获取流程处理信息
 * @param processInstanceId 流程实例id
 * @param taskKey           任务key
 * @returns {AxiosPromise}
 */
export const getHandlerTaskInfo = (taskId) => {
    return request({
            url: baseUrl + '/actProcessTask/getHandlerTaskInfo/' + taskId,
            method: 'get',

        }
    )
}
/**
 * 同意任务
 * @param taskId
 * @param data
 * @returns {*}
 */
export const taskHandlerAgree = (taskId, data) => {
    return request({
            url: baseUrl + '/actProcessTask/taskHandlerAgree/' + taskId,
            method: 'get',
            data: {opinion: data}
        }
    )
}
/**
 * 任务驳回
 * @param taskId
 * @param data
 * @returns {*}
 */
export const taskHandlerReject = (taskId, data) => {
    return request({
            url: baseUrl + '/actProcessTask/taskHandlerReject/' + taskId,
            method: 'get',
            data: {opinion: data}
        }
    )
}
/**
 * 拾取任务
 * @param taskId
 * @returns {*}
 */
export const pickUpTheTask = (taskId) => {
    return request({
            url: baseUrl + '/actProcessTask/pickUpTheTask/' + taskId,
            method: 'get',
        }
    )
}


const userTaskApi = {
    getById,
    getHandlerTaskInfo,
    taskHandlerAgree,
    taskHandlerReject,
    pickUpTheTask
}
export default userTaskApi
